package org.ssm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.smm.pojo.UserType;
import org.smm.pojo.Users;
import org.ssm.service.UserTypeService;
import org.ssm.service.UsersService;
import org.ssm.util.PageTool;

import javax.annotation.Resource;
import javax.persistence.Cacheable;
import java.util.List;
@Controller
@RequestMapping("/user")
public class UsersController {
    @Resource
    UsersService usersService;
    @Resource
    UserTypeService userTypeService;

    @RequestMapping("/list")
    public String list(Model model,Users users){
        int totalRecordCount=usersService.getRecordCount(users);
        PageTool pageTool=new PageTool(totalRecordCount,users.getCurrPageNo(),3);
        int startNum=pageTool.getStartRow();
        int pageSize=pageTool.getPageSize();
        users.setStarNum(startNum);
        users.setPageSize(pageSize);

        List<Users> list=usersService.getUserListByPage(users);
        List<UserType> plist=userTypeService.getAllUserCaTypeList();
        model.addAttribute("list",list);
        model.addAttribute("plist",plist);
        model.addAttribute("users",users);
        model.addAttribute("pageTool",pageTool);
        model.addAttribute("prePages",pageTool.getPrePages());
        model.addAttribute("nextPages",pageTool.getNextPages());

        return "/user/list";
    }
}
